package list

import "fmt"

func Sum(numbers []int) (sum int) {
	for _, number := range numbers {
		sum += number
	}
	return
}

func SumAllTails(ints ...[]int) []int {
	var sum []int
	for _, v := range ints {
		sum = append(sum, Sum(v[1:]))
	}
	return sum
}
func SumAll(ints ...[]int) []int {

	l := len(ints)
	sums := make([]int, l)
	for i, v := range ints {
		sums[i] = Sum(v)
	}
	return sums
}

func SliceTricks() {

	// copy
	a := []int{1, 2, 3, 4, 5}
	//b := make([]int, len(a))  // 一次将内存申请到位
	//copy(b, a)
	//b := append(a[:0:0],a...)
	//b := append([]int(nil),a...)

	fmt.Println("....", a[:0:0])
}
func SliceTest() {
	s := make([]string, 3)
	fmt.Println(s)

	s[0] = "a"
	s[1] = "b"
	s[2] = "c"
	fmt.Println("set:", s)
	fmt.Println("get:", s[2])
	fmt.Println("len:", len(s))

	s = append(s, "d")
	s = append(s, "e", "f")
	fmt.Println("apd:", s)
}
